package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.CustomerBean;
import com.project.service.ICustomerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("customer")
@Api(tags = "客户")
public class CustomerController {
    @Autowired
    private ICustomerService customerService;
    @ApiOperation(value = "分页查询客户")
    @RequestMapping("findByItem")
    public IPage<CustomerBean> findByItem(Integer pageNO, String customerName, String scope){
        return customerService.findByItem(pageNO, customerName, scope);
    }
    @ApiOperation(value = "根据客户id查看客户的详细信息")
    @RequestMapping("findById")
    public CustomerBean findById(Integer customerId){
        return customerService.findById(customerId);
    }
    @ApiOperation(value = "根据客户id修改负责人、负责人电话和经营范围")
    @RequestMapping("update")
    public String update(Integer customerId,String headName,String headPhone,String scope){
        customerService.update(customerId, headName, headPhone, scope);
        return "ok";
    }
    @ApiOperation(value = "添加客户、负责人电话和经营范围")
    @RequestMapping("add")
    public String add(CustomerBean customer){
        if (customerService.add(customer)){
            return "ok";
        }else {
            return "no";
        }
    }
    @ApiOperation(value = "查询所有客户名称")
    @RequestMapping("findAll")
    public List<CustomerBean> findAll(){
        return customerService.findAll();
    }
}
